home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / ScanImage2 / ScanImage2.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  10.1 KB  |  453 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.awt.image.MemoryImageSource;
  14. import java.awt.image.PixelGrabber;
  15. import java.net.MalformedURLException;
  16. import java.net.URL;
  17. import java.net.URLEncoder;
  18.  
  19. public class ScanImage2 extends Applet implements Runnable, MouseListener {
  20.    boolean loaded;
  21.    Thread thread;
  22.    Image image;
  23.    Image buffer;
  24.    // $FF: renamed from: b java.awt.Graphics
  25.    Graphics field_0;
  26.    Color backColor;
  27.    // $FF: renamed from: wi int
  28.    int field_1;
  29.    // $FF: renamed from: he int
  30.    int field_2;
  31.    int wiIm;
  32.    int heIm;
  33.    int pause;
  34.    int step;
  35.    int rad;
  36.    // $FF: renamed from: lX int
  37.    private int field_3;
  38.    // $FF: renamed from: lY int
  39.    private int field_4;
  40.    static int[] pix;
  41.    static int[] pixnew;
  42.    // $FF: renamed from: sx int
  43.    int field_5;
  44.    // $FF: renamed from: sy int
  45.    int field_6;
  46.    private String statusBarText;
  47.    private AudioClip sound;
  48.    private AudioClip clicSound;
  49.    private AudioClip enterSound;
  50.    private boolean loopSound;
  51.    private String link;
  52.    // $FF: renamed from: fm java.awt.FontMetrics
  53.    private FontMetrics field_7;
  54.    private String enterText;
  55.    private boolean isEnterTextEnabled;
  56.    private int wiEnterText;
  57.    private int enterTextHeight;
  58.    private Color enterTextColor;
  59.    private int decx;
  60.    private int decy;
  61.  
  62.    public String getAppletInfo() {
  63.       return "Name: ScanImage2\r\nAuthor: Taiji Software\r\n";
  64.    }
  65.  
  66.    public ScanImage2() {
  67.       this.backColor = Color.black;
  68.       this.pause = 200;
  69.       this.step = 10;
  70.       this.rad = 20;
  71.       ((Component)this).addMouseListener(this);
  72.    }
  73.  
  74.    public void register() {
  75.       try {
  76.          URL u = new URL("http://www.taijisoftware.com");
  77.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  78.          this.stop();
  79.       } catch (Exception e) {
  80.          System.out.println(e);
  81.          this.stop();
  82.       }
  83.    }
  84.  
  85.    public void init() {
  86.       String codeBase = null;
  87.  
  88.       try {
  89.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  90.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  91.          codeBase = codeBase.toUpperCase();
  92.       } catch (Exception var11) {
  93.       }
  94.  
  95.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  96.          String regCode = ((Applet)this).getParameter("registration_code");
  97.          if (regCode == null) {
  98.             regCode = ((Applet)this).getParameter("reg_domain");
  99.             if (regCode == null) {
  100.                this.register();
  101.             } else {
  102.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  103.                   codeBase = "WWW." + codeBase;
  104.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  105.                   codeBase = codeBase.substring(4);
  106.                }
  107.  
  108.                char[] chars = new char[codeBase.length()];
  109.                codeBase.getChars(0, codeBase.length(), chars, 0);
  110.                String key = new String("haricot");
  111.                char[] chars2 = new char[key.length()];
  112.                key.getChars(0, key.length(), chars2, 0);
  113.  
  114.                for(int i = 0; i < codeBase.length(); ++i) {
  115.                   int j;
  116.                   if (i >= key.length()) {
  117.                      j = i - key.length() * (i / key.length());
  118.                   } else {
  119.                      j = i;
  120.                   }
  121.  
  122.                   chars[i] += chars2[j];
  123.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  124.                }
  125.  
  126.                String res = new String(chars);
  127.                if (!res.equalsIgnoreCase(regCode)) {
  128.                   this.register();
  129.                }
  130.             }
  131.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  132.             this.register();
  133.          }
  134.       }
  135.  
  136.       this.getParameters();
  137.       this.image = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("image_name"));
  138.       MediaTracker tracker = new MediaTracker(this);
  139.       tracker.addImage(this.image, 0);
  140.  
  141.       try {
  142.          tracker.waitForAll();
  143.          tracker.isErrorAny();
  144.       } catch (Exception e) {
  145.          System.err.println(e);
  146.       }
  147.  
  148.       if (!this.loaded) {
  149.          this.stop();
  150.       }
  151.  
  152.       this.wiIm = this.image.getWidth(this);
  153.       this.heIm = this.image.getHeight(this);
  154.       this.decx = (this.field_1 - this.wiIm) / 2;
  155.       this.decy = (this.field_2 - this.heIm) / 2;
  156.       this.field_3 = this.wiIm / 2;
  157.       this.field_4 = this.heIm / 2;
  158.       pix = new int[this.wiIm * this.heIm];
  159.       pixnew = new int[this.wiIm * this.heIm];
  160.       PixelGrabber pixg = new PixelGrabber(this.image, 0, 0, this.wiIm, this.heIm, pix, 0, this.wiIm);
  161.  
  162.       try {
  163.          pixg.grabPixels();
  164.       } catch (InterruptedException var9) {
  165.       }
  166.  
  167.       this.image = ((Component)this).createImage(new MemoryImageSource(this.wiIm, this.heIm, pixnew, 0, this.wiIm));
  168.       this.buffer = ((Component)this).createImage(this.field_1, this.field_2);
  169.       this.field_0 = this.buffer.getGraphics();
  170.       this.field_0.setColor(this.enterTextColor);
  171.       String fontName = ((Applet)this).getParameter("enter_text_font");
  172.       if (fontName == null) {
  173.          fontName = "TimesRoman";
  174.       }
  175.  
  176.       int style = 1;
  177.       String s = ((Applet)this).getParameter("enter_text_style");
  178.       if (s != null) {
  179.          if (s.equals("bold")) {
  180.             style = 1;
  181.          } else if (s.equals("italic")) {
  182.             style = 2;
  183.          } else if (s.equals("bold_italic")) {
  184.             style = 3;
  185.          } else {
  186.             style = 0;
  187.          }
  188.       }
  189.  
  190.       this.field_0.setFont(new Font(fontName, style, this.enterTextHeight));
  191.       this.field_7 = this.field_0.getFontMetrics();
  192.       if (this.enterText != null) {
  193.          this.wiEnterText = this.field_7.stringWidth(this.enterText);
  194.       }
  195.  
  196.       if (this.sound != null) {
  197.          if (this.loopSound) {
  198.             this.sound.loop();
  199.             return;
  200.          }
  201.  
  202.          this.sound.play();
  203.       }
  204.  
  205.    }
  206.  
  207.    public void getParameters() {
  208.       this.field_1 = ((Component)this).getSize().width;
  209.       this.field_2 = ((Component)this).getSize().height;
  210.       String s = ((Applet)this).getParameter("pause");
  211.       if (s != null) {
  212.          this.pause = Integer.parseInt(s);
  213.       }
  214.  
  215.       s = ((Applet)this).getParameter("step");
  216.       if (s != null) {
  217.          this.step = Integer.parseInt(s);
  218.       }
  219.  
  220.       s = ((Applet)this).getParameter("radius");
  221.       if (s != null) {
  222.          this.rad = Integer.parseInt(s);
  223.       }
  224.  
  225.       ((Component)this).setBackground(this.getColor("background_color"));
  226.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  227.       s = ((Applet)this).getParameter("sound_name");
  228.       if (s != null) {
  229.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  230.       }
  231.  
  232.       s = ((Applet)this).getParameter("loop_sound");
  233.       if (s != null) {
  234.          if (s.equals("yes")) {
  235.             this.loopSound = true;
  236.          } else {
  237.             this.loopSound = false;
  238.          }
  239.       }
  240.  
  241.       s = ((Applet)this).getParameter("clic_sound_name");
  242.       if (s != null) {
  243.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  244.       }
  245.  
  246.       s = ((Applet)this).getParameter("enter_sound_name");
  247.       if (s != null) {
  248.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  249.       }
  250.  
  251.       this.link = ((Applet)this).getParameter("link");
  252.       this.enterText = ((Applet)this).getParameter("enter_text");
  253.       s = ((Applet)this).getParameter("enter_text_height");
  254.       if (s != null) {
  255.          this.enterTextHeight = Integer.parseInt(s);
  256.       }
  257.  
  258.       this.enterTextColor = this.getColor("enter_text_color");
  259.       if (this.enterTextColor == null) {
  260.          this.enterTextColor = Color.white;
  261.       }
  262.  
  263.    }
  264.  
  265.    public Color getColor(String param) {
  266.       String s = ((Applet)this).getParameter(param);
  267.       if (s != null) {
  268.          if (s.substring(0, 1).equals("#")) {
  269.             s = s.substring(1);
  270.             int i = Integer.parseInt(s, 16);
  271.             return new Color(i);
  272.          } else {
  273.             return null;
  274.          }
  275.       } else {
  276.          return null;
  277.       }
  278.    }
  279.  
  280.    public void start() {
  281.       if (this.thread == null) {
  282.          this.thread = new Thread(this);
  283.          this.thread.start();
  284.       }
  285.  
  286.    }
  287.  
  288.    public void stop() {
  289.       if (this.thread != null) {
  290.          this.thread = null;
  291.       }
  292.  
  293.       if (this.sound != null) {
  294.          this.sound.stop();
  295.       }
  296.  
  297.    }
  298.  
  299.    public void run() {
  300.       Thread.currentThread().setPriority(4);
  301.       this.field_5 = -1;
  302.       this.field_6 = -1;
  303.  
  304.       while(true) {
  305.          ((Component)this).repaint();
  306.  
  307.          try {
  308.             Thread.sleep((long)this.pause);
  309.          } catch (InterruptedException var1) {
  310.          }
  311.  
  312.          this.calculatePixels();
  313.          if (this.field_5 < 0 && this.field_3 < 0) {
  314.             this.field_5 = (int)(Math.random() * (double)this.step + (double)3.0F);
  315.          } else if (this.field_5 >= 0 && this.field_3 > this.wiIm - 1) {
  316.             this.field_5 = -((int)(Math.random() * (double)this.step + (double)3.0F));
  317.          }
  318.  
  319.          this.field_3 += this.field_5;
  320.          if (this.field_6 < 0 && this.field_4 < 0) {
  321.             this.field_6 = (int)(Math.random() * (double)this.step + (double)3.0F);
  322.          } else if (this.field_6 >= 0 && this.field_4 > this.heIm - 1) {
  323.             this.field_6 = -((int)(Math.random() * (double)this.step + (double)3.0F));
  324.          }
  325.  
  326.          this.field_4 += this.field_6;
  327.       }
  328.    }
  329.  
  330.    public final void paint(Graphics g) {
  331.       if (!this.loaded) {
  332.          this.field_0.setColor(Color.white);
  333.          this.field_0.drawString("loading... please wait", 1, this.field_2 / 2);
  334.          this.loaded = true;
  335.       } else {
  336.          if (this.image != null) {
  337.             this.field_0.clearRect(0, 0, this.field_1, this.field_2);
  338.             this.field_0.drawImage(this.image, this.decx, this.decy, this);
  339.             if (this.isEnterTextEnabled) {
  340.                this.field_0.drawString(this.enterText, (this.field_1 - this.wiEnterText) / 2, this.field_2 / 2);
  341.             }
  342.  
  343.             this.image = null;
  344.          }
  345.  
  346.          g.drawImage(this.buffer, 0, 0, this);
  347.       }
  348.    }
  349.  
  350.    public final void update(Graphics g) {
  351.       this.paint(g);
  352.    }
  353.  
  354.    protected final void calculatePixels() {
  355.       for(int i = 0; i < this.heIm; ++i) {
  356.          for(int j = 0; j < this.wiIm; ++j) {
  357.             int k = this.field_3 - j;
  358.             int l = this.field_4 - i;
  359.             float rayon = (float)Math.sqrt((double)(k * k + l * l));
  360.             if (rayon < (float)this.rad) {
  361.                pixnew[i * this.wiIm + j] = pix[i * this.wiIm + j];
  362.             } else {
  363.                pixnew[i * this.wiIm + j] = this.backColor.getRGB();
  364.             }
  365.          }
  366.       }
  367.  
  368.       this.image = ((Component)this).createImage(new MemoryImageSource(this.wiIm, this.heIm, pixnew, 0, this.wiIm));
  369.    }
  370.  
  371.    public URL giveURL(String url) {
  372.       try {
  373.          if (url.toUpperCase().startsWith("HTTP")) {
  374.             return new URL(url);
  375.          } else if (url.toUpperCase().startsWith("FTP")) {
  376.             int p = url.indexOf(":");
  377.             int p2 = url.indexOf(":", p + 1);
  378.             if (p2 != -1) {
  379.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  380.             }
  381.  
  382.             p = url.indexOf("%40");
  383.             if (p != -1) {
  384.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  385.             }
  386.  
  387.             return new URL(url);
  388.          } else {
  389.             return new URL(((Applet)this).getCodeBase(), url);
  390.          }
  391.       } catch (MalformedURLException e) {
  392.          System.out.println(e);
  393.          return null;
  394.       }
  395.    }
  396.  
  397.    public void mouseClicked(MouseEvent e) {
  398.    }
  399.  
  400.    public void mouseEntered(MouseEvent e) {
  401.       if (this.enterText != null) {
  402.          this.isEnterTextEnabled = true;
  403.          this.field_0.setColor(this.enterTextColor);
  404.          ((Component)this).repaint();
  405.       }
  406.  
  407.       if (this.statusBarText != null) {
  408.          ((Applet)this).showStatus(this.statusBarText);
  409.       }
  410.  
  411.       if (this.enterSound != null) {
  412.          this.enterSound.play();
  413.       }
  414.  
  415.       if (this.link != null) {
  416.          ((Component)this).setCursor(new Cursor(12));
  417.       }
  418.  
  419.    }
  420.  
  421.    public void mouseExited(MouseEvent e) {
  422.       if (this.isEnterTextEnabled) {
  423.          this.isEnterTextEnabled = false;
  424.          ((Component)this).repaint();
  425.       }
  426.  
  427.       if (this.link != null) {
  428.          ((Component)this).setCursor(new Cursor(0));
  429.       }
  430.  
  431.    }
  432.  
  433.    public void mousePressed(MouseEvent e) {
  434.       if (this.clicSound != null) {
  435.          this.clicSound.play();
  436.       }
  437.  
  438.       if (this.link != null) {
  439.          String target = ((Applet)this).getParameter("target");
  440.          if (target == null) {
  441.             target = "_blank";
  442.          }
  443.  
  444.          URL u = this.giveURL(this.link);
  445.          ((Applet)this).getAppletContext().showDocument(u, target);
  446.       }
  447.  
  448.    }
  449.  
  450.    public void mouseReleased(MouseEvent e) {
  451.    }
  452. }
  453.